// pages/home-school-chat/home-school-chat.ts
interface HomeWork {
  subjectName: string,
  homeworkStatus: boolean,
  evaluateStatus: boolean,
  chat: Chat[],
}
interface Chat {
  username: string,
  userId: number,
  avatar: string,
  upload: boolean
}
enum UserType {
  student = 0,
  teacher,
  parents,
  custom
}
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userType: UserType,
    subjectName: "课程名称",
    homeworkStatus: true,
    evaluateStatus: false,
    chatMsg: [] as Chat[],
    userId: 2,
    user: -1,
  },
  handleEvaluate(e: any) {
    wx.navigateTo({
      url: '/package-homework/pages/homework-evaluate-student/homework-evaluate-student'
    })
  },
  handleComment(e: any) {
    const { type } = e.currentTarget.dataset;
    if (type === UserType.teacher) {
      wx.navigateTo({
        url: '/package-homework/pages/homework-evaluate-teacher/homework-evaluate-teacher'
      })
    }
    if (type === UserType.parents) {
      wx.navigateTo({
        url: '/package-homework/pages/homework-evaluate-parents/homework-evaluate-parents'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.setData({
      user: app.globalData.userType
    })
    wx.request({
      url: "https://mock.presstime.cn/mock/656dbe322fef936d34630d40/yi-xiao-ping/homework",
      success: (res: {
        data: {
          data: HomeWork,
          code: number
        }
      }) => {
        const { data } = res
        const { data: homeWorkData, code } = data
        if (code === 200) {
          this.setData({
            subjectName: homeWorkData.subjectName,
            homeworkStatus: homeWorkData.homeworkStatus,
            evaluateStatus: homeWorkData.evaluateStatus,
            chatMsg: homeWorkData.chat
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    wx.pageScrollTo({
      scrollTop: 1000
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})